package com.ygou.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ygou.mapper.GoodsTypeMapper;
import com.ygou.pojo.Goods;
import com.ygou.pojo.GoodsExample;
import com.ygou.pojo.GoodsType;
import com.ygou.pojo.GoodsTypeExample;
import com.ygou.pojo.GoodsTypeExample.Criteria;
import com.ygou.service.GoodTypeServie;

@Service
public class GoodTypeServiceImpl implements GoodTypeServie{
	@Autowired
	GoodsTypeMapper gtm;
	@Override
	public List<GoodsType> showAll() {
		return gtm.selectByExample(new GoodsTypeExample());
	}

	@Override
	public List<GoodsType> show(GoodsTypeExample example) {
		return gtm.selectByExample(example);
	}

	@Override
	public boolean insert(GoodsType g) {
		// TODO Auto-generated method stub
		return gtm.insert(g)>0;
	}

	@Override
	public GoodsType selById(Long id) {
		// TODO Auto-generated method stub
		GoodsTypeExample ex=new GoodsTypeExample();
		return gtm.selectByPrimaryKey(id);
	}

	@Override
	public boolean doUpdate(GoodsType g) {
		// TODO Auto-generated method stub
		return gtm.updateByPrimaryKey(g)>0;
	}

	@Override
	public List<GoodsType> showDeleted() {
		// TODO Auto-generated method stub
		GoodsTypeExample example = new GoodsTypeExample();
		Criteria criteria = example.createCriteria();
		criteria.andStatusEqualTo(2);
		return gtm.selectByExample(example);
	}

	@Override
	public boolean doDelete(Long id) {
		GoodsType g=new GoodsType();
		g.setStatus(2);
		
		GoodsTypeExample example=new GoodsTypeExample();
		Criteria c=example.createCriteria();
		c.andIdEqualTo(id);
		
		
		return gtm.updateByExampleSelective(g, example)>0;
	}

	@Override
	public boolean ReBack(Long id) {
		GoodsType g=new GoodsType();
		g.setStatus(1);
		
		GoodsTypeExample example=new GoodsTypeExample();
		Criteria c=example.createCriteria();
		c.andIdEqualTo(id);
		
		
		return gtm.updateByExampleSelective(g, example)>0;
	}

	@Override
	public int selPCount(int sonId) {
		int count=0;
		GoodsTypeExample ex=new GoodsTypeExample();
		Criteria c=ex.createCriteria();
		c.andParentidEqualTo(new Long(sonId));
		count=gtm.countByExample(ex);
		return count;
	}

	@Override
	public int checkName(String name) {
		GoodsTypeExample ex=new GoodsTypeExample();
		Criteria c=ex.createCriteria();
		c.andNameEqualTo(name);
		return gtm.countByExample(ex);
	}

	@Override
	public GoodsType selByName(String name) {
		// TODO Auto-generated method stub
		int count=0;
		GoodsTypeExample ex=new GoodsTypeExample();
		Criteria c=ex.createCriteria();
		c.andNameEqualTo(name);
		List<GoodsType> type=gtm.selectByExample(ex);
		GoodsType g=type.get(0);
		return g;
	}

	/***********************/
	@Override
	public Map<String,Object> selectByExample() {
		Map<String,Object> map=new HashMap<>();
		GoodsTypeExample example = new GoodsTypeExample();
		Criteria criteria = example.createCriteria();
		criteria.andParentidEqualTo(new Long(1));
		map.put("jacket", gtm.selectByExample(example));
		GoodsTypeExample example2 = new GoodsTypeExample();
		criteria = example2.createCriteria();
		criteria.andParentidEqualTo(new Long(2));
		map.put("skirt", gtm.selectByExample(example2));
		GoodsTypeExample example3 = new GoodsTypeExample();
		criteria = example3.createCriteria();
		criteria.andParentidEqualTo(new Long(3));
		map.put("pants", gtm.selectByExample(example3));
		return map;
	}

	@Override
	public List<GoodsType> selectByparentid(int parentid) {
		GoodsTypeExample example = new GoodsTypeExample();
		Criteria criteria = example.createCriteria();
		criteria.andParentidEqualTo(new Long(parentid));
		return gtm.selectByExample(example);
	}

}
